<script lang="jsx" setup>
import dayjs from 'dayjs';
import { computed, nextTick, ref } from 'vue';

const commonSearchRef = ref(null);
const tableRef = ref(null);
const searchParams = ref({
  moduleNo: null,
  lotId: null,
  pnlId: null,
  time: null
});

const searchFormList = [
  {
    type: 'input',
    key: 'subEqpName',
    label: '设备名称',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    placeholder: '请输入设备名称',
    showTime: true
  },
  {
    type: 'input',
    key: 'lotNo',
    label: '批次号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    placeholder: '请输入批次号',
    showTime: true
  },
  {
    type: 'dateRangePicker',
    key: 'time',
    label: '报警日期',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    showTime: true // 显示时分秒选择
  }
];

const searchData = computed(() => {
  const params = {
    ...searchParams.value
  };
  if (searchParams.value?.time?.[0]) {
    params.startTime = dayjs(searchParams.value.time[0]).format('YYYY-MM-DD');
    params.endTime = dayjs(searchParams.value.time[0]).format('YYYY-MM-DD');
  }
  delete params.time;
  return params;
});

// 表格数据
const column = [
  {
    key: 'dataIndex',
    dataIndex: 'dataIndex',
    title: '序号',
    fixed: 'left',
    width: 70,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'fullProdNo',
    dataIndex: 'fullProdNo',
    title: ' 生产型号',
    width: 150,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'lotNo',
    dataIndex: 'lotNo',
    title: '批次号',
    width: 150,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'subEqpName',
    dataIndex: 'subEqpName',
    title: '设备名称',
    width: 150,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'dateTime',
    dataIndex: 'dateTime',
    title: '报警时间',
    width: 170,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'alarmId',
    dataIndex: 'alarmId',
    title: '报警ID',
    width: 130,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'alarmText',
    dataIndex: 'alarmText',
    title: '报警信息',
    width: 300,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'prodOrderNo',
    dataIndex: 'prodOrderNo',
    title: '工单',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'custName',
    dataIndex: 'custName',
    title: '客户名称',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'custNo',
    dataIndex: 'custNo',
    title: '客户编码',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'custProdNo',
    dataIndex: 'custProdNo',
    title: '客户型号',
    align: 'center',
    width: 230,
    checked: true,
    ellipsis: true
  }
];

function search() {
  tableRef.value.getData(1);
}

function reset() {
  nextTick(() => {
    searchParams.value = {
      subEqpName: null,
      lotNo: null,
      time: null
    };
    search();
  });
}
</script>

<template>
  <div
    class="code-whitelist-page jl-main-page min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto"
  >
    <CommonSearch
      ref="commonSearchRef"
      v-model:searchParams="searchParams"
      :form-list="searchFormList"
      :is-search="true"
      @search="search"
      @reset="reset"
    ></CommonSearch>

    <Table
      ref="tableRef"
      v-model:searchParams="searchData"
      :column="column"
      :show-row-selection="false"
      :auto-generate-uuid="true"
      :scroll="{ y: 'auto' }"
      is-init-get-data
      url="eap/xueLong/codingAlarmInfo/list"
    ></Table>
  </div>
</template>

<style lang="scss" scoped></style>
